package main;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;


public class LoadingScreen extends JFrame {

	private Image icon;
	private BufferedImage offscreen;
	
	/**
	 * Generates a splash screed
	 * @param i QNote logo
	 */
	public LoadingScreen(Image i){
		super("Loading");
		setSize(400,200);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		icon = i;
		icon = i.getScaledInstance(50, -1, Image.SCALE_SMOOTH);
		setUpOffscreen();
		setIconImage(icon);
		setLocation(400, 250);
		setUndecorated(true);
		setResizable(false);
		setVisible(true);
	}
	
	/**
	 * Draws the double buffered image
	 * "loading..." then image then "QNote Composer"
	 */
	private void setUpOffscreen() {
		offscreen = new BufferedImage(getWidth(),getHeight(), BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = (Graphics2D)offscreen.createGraphics();
		g.setBackground(Color.WHITE);
		g.setColor(Color.BLACK);
		g.clearRect(0, 0, getWidth(), getHeight());
		g.setFont(new Font("American Typewriter", Font.PLAIN, 15));
		g.drawString("Loading...", getWidth()/2-30,getHeight()/3-15);
		g.drawImage(icon, getWidth()/2-icon.getWidth(null)/2, getHeight()/2-icon.getHeight(null)/2, null);
		g.setFont(new Font("American Typewriter", Font.BOLD, 25));
		g.drawString("QNote Composer", 110, getHeight()/2+icon.getHeight(null)+10);
		
	}

	/**
	 * puts the image on the screen
	 */
	public void paint(Graphics g){
		g.drawImage(offscreen, 0, 0,null);
	}
	
}
